Socket
Socket
Sign inDemoInstall

stack-chain

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stack-chain

API for combining call site modifiers


Version published
Weekly downloads
1.3M
decreased by-38.91%
Maintainers
1
Weekly downloads
 
Created

What is stack-chain?

The stack-chain npm package allows developers to customize and extend the stack traces in Node.js. It provides a way to manipulate the call stack, add custom frames, and format stack traces to make debugging easier.

What are stack-chain's main functionalities?

Customizing Stack Traces

This feature allows you to customize the stack trace by modifying the frames. In this example, the file name in each frame is replaced with 'custom-file.js'.

const stackChain = require('stack-chain');

stackChain.extend.attach(function (error, frames) {
  frames.forEach(frame => {
    frame.getFileName = function () {
      return 'custom-file.js';
    };
  });
  return frames;
});

// Trigger an error to see the custom stack trace
try {
  throw new Error('Test error');
} catch (error) {
  console.log(error.stack);
}

Adding Custom Frames

This feature allows you to add custom frames to the stack trace. In this example, a custom frame with specific file name, line number, column number, and function name is added to the stack trace.

const stackChain = require('stack-chain');

stackChain.extend.attach(function (error, frames) {
  frames.push({
    getFileName: () => 'custom-frame.js',
    getLineNumber: () => 42,
    getColumnNumber: () => 21,
    getFunctionName: () => 'customFunction'
  });
  return frames;
});

// Trigger an error to see the custom frame in the stack trace
try {
  throw new Error('Test error');
} catch (error) {
  console.log(error.stack);
}

Formatting Stack Traces

This feature allows you to format the stack trace according to your needs. In this example, the stack trace is formatted to show the function name, file name, line number, and column number in a custom format.

const stackChain = require('stack-chain');

stackChain.format.attach(function (error, frames) {
  return frames.map(frame => {
    return `${frame.getFunctionName()} at ${frame.getFileName()}:${frame.getLineNumber()}:${frame.getColumnNumber()}`;
  }).join('\n');
});

// Trigger an error to see the formatted stack trace
try {
  throw new Error('Test error');
} catch (error) {
  console.log(error.stack);
}

Other packages similar to stack-chain

Keywords

FAQs

Package last updated on 23 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc